#include "smoker.h"

int main(int argc, char *argv[]) {
    int supplier_id = atoi(argv[1]);
    int shmid = shmget(ftok(".", 'D'), sizeof(SharedData), 0666 | IPC_CREAT);
    SharedData *shared_data = (SharedData *)shmat(shmid, NULL, 0);

    while (1) {
        P(mutex_sem);
        int combo = shared_data->current_combo;
        shared_data->current_combo = (combo + 1) % NUM_SMOKERS;
        V(mutex_sem);

        // 触发对应抽烟者
        V(smoker_sem[combo]);
        printf("Supplier %d provides combo %d\n", supplier_id, combo);

        // 等待抽烟完成
        P(supplier_sem);
    }
    return 0;
}
